package top.wenzz.commons.utils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Whitelist;

/**
 * Created by 钟廷员 on 2017/7/21.
 */
public class HtmlUtils {

    private static final Whitelist whitelist = Whitelist.relaxed();
    private static final String baseUri = "https://qTXNk4xBeBRtPy6ZSNtpMFbab1fPYMi7kr4NXoEfew4Y6cQZPR." +
            "6el2qxJF3R2223Vhj3Beb0TTmixOxPgPsCEo0HZhWYrFaVyw25." +
            "Phg9ikih1NeHNfRzQ1QNQv7OvkWGaJamTZmzJPa8gQvabRXMEr." +
            "tgbJCTjqz5DHsTKEYqeNLqgegXwajAOjb6M9YVbiZLlHUrCoUg/";

    public static String cleanSafeHtml(String htmlStr) {
        Document doc = Jsoup.parseBodyFragment(htmlStr);
        return Jsoup.clean(doc.html(), baseUri, whitelist);
    }

    public static void main(String[] args) {
        String html = "<p style='c:1'>Parsed HTML into a doc 1.</p><p>Parsed HTML into a doc 2.</p>" +
                "<script src=\"http://static.blog.csdn.net/scripts/blog_static_head.min.js\" type=\"text/javascript\">alert(1);</script>" +
                "<a href='/ab/a'></a>";
        System.out.println(cleanSafeHtml(html).replace(baseUri, ""));
    }
}